
#include <iostream>
#include <initializer_list>

/*
 * 传入参数写在{}内
 * 同一个initializer_list中的参数具有相同的类型
 */
int sum(std::initializer_list<int> il, bool option){
    int sum = 0;
    if(option){
        for(auto p = il.begin(); p != il.end(); p++){
            sum += *p;
        }
        return sum;
    }else{
        for(auto& elem : il){
            sum += elem;
        }
        return sum;
    }
}


int main(int argc, char* argv[]){
    std::cout << "sum: " << sum({1, 2, 3}, true) << std::endl;
    std::cout << "sum: " << sum({1, 2, 3}, false) << std::endl;
    return 0;
}


